package keshe;

public class SparseMatrix {

        public TripleNode data[];
        public int rows;
    public int cols;
    public int nums;


    public SparseMatrix( int maxSize){
            data = new TripleNode[maxSize];
            for (int i = 0; i < data.length; i++) {
                data[i] = new TripleNode();
            }
            rows = 0;
            cols = 0;
            nums = 0;
        }

   public SparseMatrix( int mat[][]){
            int i, j, k = 0, count = 0;
            rows = mat.length;
            cols = mat[0].length;
            for (i = 0; i < mat.length; i++) {
                for (j = 0; j < mat[i].length; j++) {
                    if (mat[i][j] != 0) {
                        count++;
                    }
                }
            }
            nums = count;
            data = new TripleNode[nums];
            for (i = 0; i < mat.length; i++) {
                for (j = 0; j < mat[i].length; j++) {
                    if (mat[i][j] != 0) {
                        data[k] = new TripleNode(i, j, mat[i][j]);
                        k++;
                    }
                }
            }
        }



    }










